package cn.secby.wms.controller;


import cn.secby.common.core.utils.poi.ExcelUtil;
import cn.secby.common.core.web.controller.BaseController;
import cn.secby.common.core.web.domain.AjaxResult;
import cn.secby.common.log.annotation.Log;
import cn.secby.common.log.enums.BusinessType;
import cn.secby.common.security.annotation.RequiresPermissions;
import cn.secby.wms.domain.Area;
import cn.secby.wms.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区Controller
 * 
 * @author hushuo
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/area")
public class AreaController extends BaseController
{
    @Autowired
    private IAreaService areaService;

    /**
     * 查询地区列表
     */
    @RequiresPermissions("wms:area:list")
    @GetMapping("/list")
    public AjaxResult list(Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        return success(list);
    }

    /**
     * 导出地区列表
     */
    @RequiresPermissions("wms:area:export")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        util.exportExcel(response, list, "地区数据");
    }

    /**
     * 获取地区详细信息
     */
    @RequiresPermissions("wms:area:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(areaService.selectAreaById(id));
    }

    /**
     * 新增地区
     */
    @RequiresPermissions("wms:area:add")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Area area)
    {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改地区
     */
    @RequiresPermissions("wms:area:edit")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Area area)
    {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除地区
     */
    @RequiresPermissions("wms:area:remove")
    @Log(title = "地区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(areaService.deleteAreaByIds(ids));
    }
}
